package com.hh.controller;

import com.test.Recorder;
import hh.util.CommonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author: huanghuai
 * @Date: 2020/7/20
 */
@RestController
@RequestMapping("/test")
public class TestController {

    Logger log = LoggerFactory.getLogger(TestController.class);

    Recorder recorder = new Recorder(10000);

    @RequestMapping(value = "/media", method = RequestMethod.GET
            // ,produces = "text/xm111l"
            , consumes = {"*/*", "appl2ication/*"}
    )
    @ResponseBody

    public Object testMediaType() throws InterruptedException {
        Thread.sleep(100);
        return recorder.record(1);
    }

    @GetMapping("/get")
    public Object get(@RequestParam("data") String data) throws Exception {
        String[] ss = data.split(",");
        List<String> list = CommonUtil.newArrayList(ss);
//        Thread.sleep(1500);
//        CommonUtil.allIsEmpty(123);
        Object d = get2(list);
        return d;

    }

    private Object get2(List<String> list) {
        List<String> collect = list.stream().map(e -> e).collect(Collectors.toList());

        System.out.println(collect);
        return collect;

    }


    public static class U {
        private String name;
        private int age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }


    public static void main(String[] args) throws Exception {
        jedisTest2();
    }


    public static void jedisTest2() throws InterruptedException {

        JedisPoolConfig config = new JedisPoolConfig();

        config.setMaxTotal(100);

        config.setTestOnBorrow(false);

        config.setMaxWaitMillis(2000);

        JedisPool jedisPool = new JedisPool(config, "localhost", 6379, 2000, "root");

        Jedis jedis = jedisPool.getResource();

        System.out.println(jedis.get("adf"));

        java.lang.Thread.sleep(3000);

        System.out.println(jedis.get("adf"));

    }
}
